from flask.ext.wtf import CSRFProtect
from flask import Flask,session
from flask.ext.sqlalchemy import SQLAlchemy
from redis import StrictRedis
from flask_session import Session
from flask_script import Manager
from flask_migrate import Migrate,MigrateCommand

class Config(object):
    DEBUG = True
    SECRET_KEY = "6+YiSyAvMu/sNo4Z8ASZ8goit56O79NiF7aEfa43ywcayu1Oo4+Y+GCtDodGY8WQ"
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information77"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    #redis配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379
    SESSION_TYPE = "redis"
    #SESSION保存配置
    SESSION_TYPE = 'redis'
    #开启session签名
    SESSION_USE_SIGNER = True

    #指定session保存到 redis

    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    #设施需要过期
    SESSION_PERMANENT = False
    #设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2



app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
#初始化redis储存对象
redis_store = StrictRedis(host=Config.REDIS_HOST,port=Config.REDIS_PORT)
CSRFProtect(app)
#设置session保存制定位置
Session(app)

manager = Manager(app)
#将迁移命令增加到manager
manager.add_command('db',MigrateCommand)


@app.route('/')
def index():
    session["name"] = "itheima"

    return "index11111"

if __name__ == "__main__":
    app.run()